<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="uct" uri="/WEB-INF/uct.tld" %>
<%@ taglib prefix="portal" uri="/WEB-INF/portal.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/sale/include/common-base.jsp"%>
  <title>平台资金总览-${titleName}</title>
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

	<!-- top start -->
	<%@include file="/common/sale/top.jsp" %>
	<!-- top end -->
	<!-- left start -->
	<%@include file="/common/sale/left.jsp" %>
	<!-- left end-->

	<div class="content-wrapper">
	<!--  
		<ol class="breadcrumb bgblue">
			<li>
				<span class="label label-danger font14" >结算管理 / 平台资金总览</span>
			</li>
		</ol>
	-->	
	<!-- Main start -->

<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<!------  start ------->
			<div class="box box-info">
				<!--搜索title  start --> 
				<div class="box-header with-border">
				<h3 class="box-title"><i class="fa fa-money"></i> 平台资金总览</h3>
					<div class="box-tools pull-right">
					<!-- <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
					</button>
					<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
					-->
					</div>
				</div>
				<!--搜索title  end --> 
				<div class="box-body">
					<form class="form-horizontal" role="form" id="viewForm">
					<div class="box-body">
						<!-- Custom Tabs -->
						<div class="callout callout-danger">
							<i class="fa fa-info white"></i>
							温馨提示：平台初始化给运营商分配虚拟资金账户，以备交易过程中记录相关费用。
						</div>
						<div class="form-group">
							<label class="col-sm-2 text-right" >资金账号：</label>
							<span class="col-sm-8"  id="fundsUserName"></span>
						</div>
						<div class="form-group">
							<label class="col-sm-2 text-right" >账户名称：</label>
							<span class="col-sm-8" id="fundsRealName"></span>
						</div>
						<div class="form-group">
							<label class="col-sm-2 text-right" >账户状态：</label>
							<div class="col-sm-8 text_l" id="fundsStatus"></div>
						</div>
						<div class="form-group ">
							<!-- 总金额 start -->
							<div class="col-md-4" >
								<div class="info-box bg-aqua">
									<span class="info-box-icon"><i class="fa fa-usd mar_t22"></i></span>
									<div class="info-box-content">
										<h5 class="info-box-text">总金额</h5>
										<p class="info-box-number">￥<span id="fundsAmtTotal"></span></p>
										<div class="progress">
											<div class="progress-bar" style="width: 70%"></div>
										</div>
									</div>
								</div>
							</div>
							<!-- 总金额  end -->
							<!-- 可用金额 start -->
							<div class="col-md-4" >
							<div class="info-box bg-yellow">
							<span class="info-box-icon"><i class="fa fa-rmb  mar_t22"></i></span>
							<div class="info-box-content">
							<h5 class="info-box-text">可用金额</h5>
							<p class="info-box-number">￥<span id="fundsM1"></span></p>
							<div class="progress">
							<div class="progress-bar" style="width: 70%"></div>
							</div>
							</div>
							</div>
							</div>
							<!-- 可用金额  end -->
							<!-- 冻结金额 start -->
							<div class="col-md-4" >
								<div class="info-box bg-red">
								<span class="info-box-icon"><i class="fa fa-try mar_t22"></i></span>
									<div class="info-box-content">
										<h5 class="info-box-text">冻结金额</h5>
										<p class="info-box-number">￥<span id="fundsM2"></span></p>
										<div class="progress">
											<div class="progress-bar" style="width: 0%"></div>
										</div>
									</div>
								</div>
							</div>
							<!-- 冻结金额  end -->
						</div>
						<div class="form-group text-center">
							<button type="button" class="btn btn-success btn-lg" onclick="toDetail()"><i class="fa fa-search"></i> 查看明细</button>
						</div>
						<!-- nav-tabs-custom -->
					</div>
					<div style="display:none;">
						<input type="" id="userId" name="userId" value="" />
						<input type="" id="userEname" name="userEname" value="" />
						<input type="" id="userCname" name="userCname" value="" />
						<input type="" id="settleAccountNo" name="settleAccountNo" value="" />
						<input type="" id="userFundPas" name="userFundPas" value="1" />
					</div>
					</form>
				</div>
			</div>
			<!-------  end -------->
		
<script>
var clickMenu= 'funds-platform-all';
var userName = "<portal:config varKey='jys_funds_id'/>";//"6228000000000000";
var userEname = 'nlwadmin';
//userName = "6228000000000002";
$(function () {
	var realName = "本交易平台资金账户";
	
	$("#fundsUserName").text(userName);
	$("#settleAccountNo").val(userName);
	$("#fundsRealName").text(realName);
	//监测平台账户是否初始化资金账号了
	checkPlateFormFunds();
  });

//查看明细
function toDetail(){
	var url = "${ctx}/sendPage/sale/admin/funds/funds-platform-list";
	window.location.href=url;
}

//监测平台账户是否初始化资金账号了
function checkPlateFormFunds(){
	var index_load = layer.load(1, {shade: false});
	$.ajax({
		type:'get',dataType:'json',
		url: common_list_url+'?doCode=F003',
		async: false,data: {"settleAccountNo":userName,f:new Date().getTime()},
		success:function(result)	{
			console.log(result);
			layer.close(index_load);
			var flag = result.flag;
			if("T"==flag){
				$("#fundsStatus").html("<label class='fx1'>正常</label>");
				getPlateFormFundsBal();
			}else if("F1"==flag){
				$("#fundsStatus").html("<label class='red'>未开通</label> &nbsp;&nbsp;<button type=\"button\" class=\"btn btn-danger\" onclick=\"openPlateFormFunds()\">点此初始化</button>");
			}else{
				$("#fundsStatus").html("<label class='red'>正在检测中...</label>");
			}
		}
	});
}

//获取平台资金余额
function getPlateFormFundsBal(){
	var index_load = layer.load(1, {shade: false});
	$.ajax({
		type:'get',dataType:'json',
		url: common_list_url+'?doCode=F004&settleAccountNo='+userName,
		async: false,data: {f:new Date().getTime()},
		success:function(result)	{
			console.log(result);
			layer.close(index_load);
			var flag = result.flag;
			if("T"==flag){
				var obj = result.msg;
		  		$("#fundsAmtTotal").text(fmoney(obj.amtTotal*1/100));
		  		$("#fundsM1").text(fmoney(obj.m1*1/100));
		  		$("#fundsM2").text(fmoney(obj.m2*1/100));
			}
		}
	});
}

//初始化开通平台自己账户
function openPlateFormFunds(){
	//根据userEname获取账户信息
	getUserInfoByUserEname();
	var index_load = layer.load(1, {shade: false});
	$.ajax({
		type:"post",
		dataType:"json",
		url: common_submit_url+"?doCode=F010",
		async: false,
		data: $("#viewForm").serialize(),
		success:function(result)	{
			console.log(result);
			layer.close(index_load);
			var flag = result.flag;
			if("T"==flag){
				//刷新页面
				checkPlateFormFunds();
				layer.msg('平台资金账号创建成功！', 
					{
						time: 3000, //3s后自动关闭
						offset: '200px'
					},
					function(){layer.closeAll();}
				);
			}
		}
	});
}
//根据userEname获取账户信息
function getUserInfoByUserEname(){
	var index_load = layer.load(1, {shade: false});
	$.ajax({
		 type:'get',
	    url:common_info_url,
	    data:{'uctUser.w_userEname':userEname,'pageName':'user-list.jsp','formName':'searchForm',f:new Date().getTime()},
	    dataType:'json',
	    async:false,
		success:function(myData)	{
			console.log(myData);
			layer.close(index_load);
			$("#userId").val(myData.userId);
			$("#userEname").val(myData.userEname);
			$("#userCname").val(myData.userCname);
		}
	});
}
</script>

</div>
	</div>
</section>
<!-- Main end -->
</div>
  
  
  <!-- /.content-wrapper -->
  <!-- foot start -->
  <%@include file="/common/sale/foot.jsp" %>
  <!-- foot start -->
  
</body>
</html>
